home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Inne / Gry / Carnage_Contest / scripts / CC Original / weapons / Heavy Airstrike.lua < prev    next >
Encoding:
Text File  |  2010-08-31  |  4.4 KB  |  125 lines

  1. --------------------------------------------------------------------------------
  2. -- Weapon Heavy Airstrike + Projectile Cluster
  3. -- Original Carnage Contest Weapon
  4. -- Script by DC, September 2009, www.UnrealSoftware.de
  5. --------------------------------------------------------------------------------
  6.  
  7. -- Setup Tables
  8. if cc==nil then cc={} end
  9. cc.heavyairstrike={}
  10. cc.heavyairstrike.cluster={}
  11.  
  12. -- Load & Prepare Ressources
  13. cc.heavyairstrike.gfx_wpn=loadgfx("weapons/rc.bmp")                                -- Weapon Image
  14. setmidhandle(cc.heavyairstrike.gfx_wpn)
  15. cc.heavyairstrike.gfx_icon=loadgfx("weapons/heavyairstrikeicon.png")            -- Weapon Icon
  16. setmidhandle(cc.heavyairstrike.gfx_icon)
  17. cc.heavyairstrike.gfx_pro=loadgfx("weapons/cluster.bmp")                        -- Projectile Image
  18. setmidhandle(cc.heavyairstrike.gfx_pro)
  19. cc.heavyairstrike.sfx_attack=loadsfx("airstrike.ogg")                            -- Attack Sound
  20.  
  21. --------------------------------------------------------------------------------
  22. -- Weapon: Heavy Airstrike
  23. --------------------------------------------------------------------------------
  24.  
  25. cc.heavyairstrike.id=addweapon("cc.heavyairstrike","Heavy Air Strike",cc.heavyairstrike.gfx_icon,0,3)    -- Add Weapon (0 uses, first in round 3)
  26.  
  27. function cc.heavyairstrike.draw()                                                -- Draw
  28.     setblend(blend_alpha)
  29.     setalpha(1)
  30.     setcolor(255,255,255)
  31.     drawinhand(cc.heavyairstrike.gfx_wpn,7,0)
  32.     -- HUD Positioning
  33.     if weapon_shots==0 then
  34.         hudpositioning(pos_invisible)
  35.     end
  36. end
  37.  
  38. function cc.heavyairstrike.attack(attack)                                        -- Attack
  39.     if (weapon_shots<=0) and (weapon_position==1) then
  40.         -- No more weapon switching!
  41.         useweapon(0)
  42.         playsound(cc.heavyairstrike.sfx_attack)
  43.         weapon_shots=weapon_shots+1
  44.         -- Attack
  45.         for i=0,2,1 do
  46.             for j=-2,2,1 do
  47.                 pid=createprojectile(cc.heavyairstrike.cluster.id)
  48.                 projectiles[pid]={}
  49.                 projectiles[pid].x=weapon_x+(j*15)
  50.                 projectiles[pid].y=-500-(i*500)
  51.                 projectiles[pid].sx=0
  52.                 projectiles[pid].sy=5.0
  53.                 if i==0 and j==0 then projectiles[pid].follow=1 end
  54.             end
  55.         end
  56.         -- End Turn
  57.         endturn()
  58.     end
  59. end
  60.  
  61. --------------------------------------------------------------------------------
  62. -- Projectile: Cluster
  63. --------------------------------------------------------------------------------
  64.  
  65. cc.heavyairstrike.cluster.id=addprojectile("cc.heavyairstrike.cluster")    -- Add Projectile
  66.  
  67. function cc.heavyairstrike.cluster.draw(id)                                -- Draw
  68.     -- Setup draw mode
  69.     setblend(blend_alpha)
  70.     setalpha(1)
  71.     setcolor(255,255,255)
  72.     setscale(1,1)
  73.     -- Calculate projectile rotation
  74.     setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
  75.     -- Draw projectile
  76.     drawimage(cc.heavyairstrike.gfx_pro,projectiles[id].x,projectiles[id].y)
  77. end
  78.  
  79. function cc.heavyairstrike.cluster.update(id)                            -- Update
  80.     rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
  81.     -- Particle Tail
  82.     particle(p_smoke,projectiles[id].x-math.sin(math.rad(rot))*7,projectiles[id].y+math.cos(math.rad(rot))*7)
  83.     particlespeed(math.random(-2,2)*0.1,math.random(-2,2)*0.1)
  84.     particlefadealpha(0.05)
  85.     -- Gravity influence on speed
  86.     projectiles[id].sy=projectiles[id].sy+getgravity()
  87.     -- Move (in substep loop for optimal collision precision)
  88.     msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/3)
  89.     msubx=projectiles[id].sx/msubt
  90.     msuby=projectiles[id].sy/msubt
  91.     for i=1,msubt,1 do
  92.         projectiles[id].x=projectiles[id].x+msubx
  93.         projectiles[id].y=projectiles[id].y+msuby
  94.         -- Collision
  95.         if collision(col3x3,projectiles[id].x,projectiles[id].y)==1 then
  96.             -- Cause damage
  97.             arealdamage(projectiles[id].x,projectiles[id].y,70,30)
  98.             -- Destroy terrain
  99.             terrainexplosion(projectiles[id].x,projectiles[id].y,30,1)
  100.             -- Crater
  101.             grey=math.random(0,40)
  102.             if math.random(0,1)==1 then
  103.                 terrainalphaimage(gfx_crater100,projectiles[id].x,projectiles[id].y,math.random(5,7)*0.1,grey,grey,grey)
  104.             else
  105.                 terrainalphaimage(gfx_crater125,projectiles[id].x,projectiles[id].y,math.random(5,7)*0.1,grey,grey,grey)
  106.             end
  107.             -- Free projectile
  108.             freeprojectile(id)
  109.             break
  110.         end
  111.         -- Water
  112.         if (projectiles[id].y)>getwatery()+5 then
  113.             -- Effects
  114.             particle(p_waterhit,projectiles[id].x,projectiles[id].y)
  115.             playsound(sfx_hitwater1)
  116.             -- Free projectile
  117.             freeprojectile(id)
  118.             break
  119.         end
  120.     end
  121.     -- Scroll to projectile
  122.     if projectiles[id].follow==1 then
  123.         scroll(projectiles[id].x,projectiles[id].y)
  124.     end
  125. end